using System;
using Castle.MonoRail.Framework;
using Yama.HelloWorld.Rails.Controllers;
using Yama.MVC.MonoRail.Filters;

namespace Yama.HelloWorld.Rails.Filters
{
    public class AccessDatabaseInFilterAttribute:Attribute, IActionFilter
    {
        #region Implementation of IActionFilter

        public bool PerformBeforeAction(IEngineContext context, IController controller, IControllerContext controllerContext)
        {
            ((HomeController) controller).VisitDao.CountVisitsForUrl("");

            return true;
        }

        public void PerformAfterAction(IEngineContext context, IController controller, IControllerContext controllerContext)
        {
        }

        public void PerformAfterRendering(IEngineContext context, IController controller, IControllerContext controllerContext)
        {
        }

        public ExecuteWhen ExecuteWhen
        {
            get { return ExecuteWhen.BeforeAction; }
        }

        #endregion
    }
}